1 =============================================================================
2 Windows APPLICATION: CSImageFullScreenSlideShow Overview
3 =============================================================================
5 /////////////////////////////////////////////////////////////////////////////
8 The sample demonstrates how to display image slideshow in a Windows Forms
9 application. It also shows how to enter the full screen mode to slide-show
13 /////////////////////////////////////////////////////////////////////////////
16 Step1. Build and run the sample project in Visual Studio 2010.
18 Step2. Prepare some image files. Click the "Open Folder..." button and
19 select the path which includes image files.
21 Step3. Click "Previous" button and "Next" button to make image files
24 Step4. Left-click the "Settings" button and select the internal between the
25 displayed image files for Timer control in order to display them
26 with a fixed interval time. Finally, left-click the "Start Slideshow"
27 button to make the image files displayed one by one.
29 Step5. Left-click the "Full Screen" button to display images in the full
30 screen mode. Press the "ESC" key to leave the full screen mode.
33 /////////////////////////////////////////////////////////////////////////////
36 1. When user selects the root folder of image files, the sample enumerates
37 the image files in the folder using the stack-based iteration method
38 demonstrated in this MSDN article:
39 http://msdn.microsoft.com/en-us/library/bb513869.aspx
40 The sample does not use
41 Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
42 to enumerate the files because it will abort when the user does not have
43 access permissions for certain directories or files in the root folder.
45 public static string[] GetFiles(string path, string searchPattern)
47 string[] patterns = searchPattern.Split(';');
48 List<string> files = new List<string>();
49 foreach (string filter in patterns)
51 // Iterate through the directory tree and ignore the
52 // DirectoryNotFoundException or UnauthorizedAccessException
54 // http://msdn.microsoft.com/en-us/library/bb513869.aspx
56 // Data structure to hold names of subfolders to be
57 // examined for files.
58 Stack<string> dirs = new Stack<string>(20);
60 if (!Directory.Exists(path))
62 throw new ArgumentException();
66 while (dirs.Count > 0)
68 string currentDir = dirs.Pop();
72 subDirs = Directory.GetDirectories(currentDir);
74 // An UnauthorizedAccessException exception will be thrown
75 // if we do not have discovery permission on a folder or
76 // file. It may or may not be acceptable to ignore the
77 // exception and continue enumerating the remaining files
78 // and folders. It is also possible (but unlikely) that a
79 // DirectoryNotFound exception will be raised. This will
80 // happen if currentDir has been deleted by another
81 // application or thread after our call to Directory.Exists.
82 // The choice of which exceptions to catch depends entirely
83 // on the specific task you are intending to perform and
84 // also on how much you know with certainty about the
85 // systems on which this code will run.
86 catch (UnauthorizedAccessException)
90 catch (DirectoryNotFoundException)
97 files.AddRange(Directory.GetFiles(currentDir, filter));
99 catch (UnauthorizedAccessException)
103 catch (DirectoryNotFoundException)
108 // Push the subdirectories onto the stack for traversal.
109 // This could also be done before handing the files.
110 foreach (string str in subDirs)
117 return files.ToArray();
120 2. The sample displays the images in a PictureBox.
123 /// Show the image in the PictureBox.
125 public static void ShowImage(string path, PictureBox pct)
127 pct.ImageLocation = path;
131 /// Show the previous image.
133 private void ShowPrevImage()
135 ShowImage(this.imageFiles[(--this.selected) % this.imageFiles.Length], this.pictureBox);
139 /// Show the next image.
141 private void ShowNextImage()
143 ShowImage(this.imageFiles[(++this.selected) % this.imageFiles.Length], this.pictureBox);
146 A timer is used to automatically slideshow the images.
149 /// Show the next image at every regular intervals.
151 private void timer_Tick(object sender, EventArgs e)
156 2. To slide-show images in the full-screen mode, the sample provides a helper
157 class 'FullScreen'. FullScreen.cs contains two public methods:
159 EnterFullScreen - used to make a Windows Form display in the full screen.
160 LeaveFullScreen - used to restore a Windows Form to its original state.
163 /// Maximize the window to the full screen.
165 public void EnterFullScreen(Form targetForm)
169 Save(targetForm); // Save the original form state.
171 targetForm.WindowState = FormWindowState.Maximized;
172 targetForm.FormBorderStyle = FormBorderStyle.None;
173 targetForm.TopMost = true;
174 targetForm.Bounds = Screen.GetBounds(targetForm);
181 /// Leave the full screen mode and restore the original window state.
183 public void LeaveFullScreen(Form targetForm)
187 // Restore the original Window state.
188 targetForm.WindowState = winState;
189 targetForm.FormBorderStyle = brdStyle;
190 targetForm.TopMost = topMost;
191 targetForm.Bounds = bounds;
193 IsFullScreen = false;
198 /////////////////////////////////////////////////////////////////////////////
201 How to: Iterate Through a Directory Tree (C# Programming Guide)
202 http://msdn.microsoft.com/en-us/library/bb513869.aspx
204 Screen.GetBounds Method
205 http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.getbounds.aspx
208 /////////////////////////////////////////////////////////////////////////////